package task3.source;

import java.awt.Label;
import java.util.Observer;
import java.util.Vector;
import task3.util.AbstractBean;
import task3.util.FilterObservable;
import task3.util.InputEvent;
import task3.util.InputListener;

public class BSource
  extends AbstractBean
  implements Observer
{
  private static final long serialVersionUID = -5843117722322431929L;
  private Source _source;
  
  public BSource()
  {
    this._source = new Source();
    this._source.getObservable().addObserver(this);
    this._textField.setText("Source");
  }
  
  public String getFileName()
  {
    return this._source.getFileName();
  }
  
  public void setFileName(String fileName)
  {
    this._source.setFileName(fileName);
    run();
  }
  
  public void addListener(InputListener l)
  {
    this._listeners.add(l);
    this._source.setOutput(l.getWriteable());
    
    InputEvent event = new InputEvent(this._source);
    for (InputListener i : this._listeners) {
      i.inputChanged(event);
    }
    run();
  }
  
  public void removeListener(InputListener l)
  {
    this._listeners.remove(l);
  }
  
  public void run()
  {
    try
    {
      this._source.run();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}
